<extend name="./public/frame.html"/>
<block name="content">
    <blockquote class="layui-elem-quote search">
        <div class="layui-inline">
            <input type="text" name="title" id="title" placeholder="活动名称" class="layui-input">
        </div>
        <div class="layui-inline">
            <input type="text" class="layui-input" id="start_time" placeholder="活动开始时间">
        </div>
        <div class="layui-inline">
            <input type="text" class="layui-input" id="end_time" placeholder="活动结束时间">
        </div>
        <div class="layui-inline">
            <select id="status" name="status" class="layui-input"lay-filter="activity_model" style="width: 150px;">
                <option value="">活动状态</option>
                <option value="0">未开始</option>
                <option value="1">进行中</option>
                <option value="2">已结束</option>
            </select>
        </div>

        <div class="layui-inline">
            <button class="layui-btn" data-type="search">搜索</button>
            <button class="layui-btn layui-btn-normal" data-url="{:url('add')}" onclick="add_t(this, '添加活动')">
                添加活动
            </button>
        </div>
    </blockquote>
    <table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('ActivityNews/index')}', page: true, limit: 10, id:'ActivityNews'}"  lay-filter="ActivityNews">
        <thead>
            <tr>
                <th lay-data="{field:'id', width:70,fixed: true, sort: true,align:'center',fixed: true}">ID</th>
                <th lay-data="{field:'title', width:180,align:'center'}">活动标题</th>
                <th lay-data="{field:'description', width:280,align:'center'}">活动简述</th>
                <th lay-data="{field:'region_name', width:150,align:'center'}">显示城市</th>
                <th lay-data="{field:'start_time', width:120,align:'center'}">活动开始时间</th>
                <th lay-data="{field:'end_time', width:120,align:'center'}">活动结束时间</th>
                <th lay-data="{field:'admin_name', width:80,align:'center'}">操作人</th>
                <th lay-data="{field:'create_time', width:160,align:'center'}">操作时间</th>
                <th lay-data="{field:'status', width:160,align:'center'}">活动状态</th>
                <th lay-data="{fixed:'right', toolbar: '#barDemo', width:210, align:'center'}">操作</th>
            </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit" style="width: 50px">修改</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" style="width: 50px">删除</a>
    </script>
    <script>
        // && d.activity_type !=2
        layui.use(['form', 'table', 'laydate'], function () {
            var table = layui.table, form = layui.form, laydate = layui.laydate;
            laydate.render({
                elem: '#start_time' //指定元素
            });

            laydate.render({
                elem: '#end_time' //指定元素
            });
            table.on('tool(ActivityNews)', function (obj) {
                var data = obj.data;
                var id = data.id;
                if (obj.event === 'edit') {
                    layer.open({
                        type: 2,
                        title: '编辑活动',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/ActivityNews/edit","id=")}' + id //iframe的url
                    });
                } else if (obj.event === 'del') {
                    layer.confirm('确定删除吗?', function (index) {
                        var url = '{:url("/admin/ActivityNews/del","id=")}' + id
                        $.get(url, function (data) {
                            if (data.status == 1) {
                                layer.msg(data.msg, {'icon': 1});
                                window.location.reload();
                            } else {
                                layer.msg(data.msg, {'icon': 2});
                            }
                        }, 'json')
                        layer.close(index);
                    })
                }
            });

            //搜索
            $('.layui-btn').on('click', function () {
                var title = $("#title").val();
                var start_time = $("#start_time").val();
                var end_time = $("#end_time").val();
                var status = $("#status").val();
                table.reload('ActivityNews', {
                    url: '/admin/ActivityNews/index', where: {
                        "title": title,
                        "start_time": start_time,
                        "end_time": end_time,
                        "status": status,
                    }
                });
            });
        });
    </script>
</block>
